package spring.demo.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

@Component
public class CustomEventPublisher {
    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    public void doSomethingAndPublishAnEvent(final String message) {
        System.out.println("Publishing custom event.: " + message);
        MyEnvent customEvent = new MyEnvent(message);
        applicationEventPublisher.publishEvent(customEvent);
    }
}